package com.wsse.common.tool;

import java.util.Random;

public class CheckCodeTool {
    /**
     * 获取一个由随机数字组成的字符串
     * @param length 字符串长度
     * @return
     */
    public static String getNumberCode(int length){
        String str = "0123456789";
        String code = "";
        Random r = new Random();
        for (int i = 0; i < length; i++) {
            code += str.charAt(r.nextInt(str.length()));
        }
        return code;
    }

    /**
     * 获取一个由随机数字和字母组合的字符串
     * @param length 字符串长度
     * @return
     */
    public static String getCode(int length) {
        String str = "ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        String code = "";
        Random r = new Random();
        for (int i = 0; i < length; i++) {
            code += str.charAt(r.nextInt(str.length()));
        }
        return code;
    }
}
